# coupon_page.py
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class CouponPage:
    def __init__(self, driver):
        self.driver = driver
        self.url = 'http://example.com/coupons'
        self.coupon_code_input_locator = (By.ID, 'coupon-code-input')  # 优惠码输入框定位器
        self.apply_coupon_button_locator = (By.ID, 'apply-coupon-button')  # 应用优惠券按钮定位器
        self.coupon_status_message_locator = (By.ID, 'coupon-status-message')  # 优惠券状态消息定位器
        self.coupon_details_locator = (By.ID, 'coupon-details')  # 优惠券详情定位器
        self.remove_coupon_button_locator = (By.ID, 'remove-coupon-button')  # 移除优惠券按钮定位器
        self.cart_total_locator = (By.ID, 'cart-total')  # 购物车总价定位器
        self.coupon_discount_locator = (By.ID, 'coupon-discount')  # 优惠券折扣定位器

    # 导航到优惠券页面
    def navigate(self):
        self.driver.get(self.url)

    # 输入优惠码
    def enter_coupon_code(self, code):
        self.driver.find_element(*self.coupon_code_input_locator).send_keys(code)

    # 应用优惠码
    def apply_coupon(self):
        self.driver.find_element(*self.apply_coupon_button_locator).click()

    # 获取优惠券状态消息
    def get_coupon_status_message(self):
        return self.driver.find_element(*self.coupon_status_message_locator).text

    # 获取优惠券详情
    def get_coupon_details(self):
        return self.driver.find_element(*self.coupon_details_locator).text

    # 移除优惠券
    def remove_coupon(self):
        self.driver.find_element(*self.remove_coupon_button_locator).click()

    # 获取购物车总价
    def get_cart_total(self):
        return float(self.driver.find_element(*self.cart_total_locator).text.replace('$', ''))

    # 获取优惠券折扣金额
    def get_coupon_discount(self):
        return float(self.driver.find_element(*self.coupon_discount_locator).text.replace('$', ''))